﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DockSample
{
    class RelationsDAO : BaseDAO
    {
        MemoryDAO mDAO = new MemoryDAO();


        public void AddAllAttrAndMethodRelations()
        {
            MainForm mainForm = SystemVar.mainForm;
            foreach (DummyModelForm form in mainForm.modelFormList)
            {
                foreach (OriginalDiagram diagram in form.diagramList)
                {
                    if (diagram is ObjectDiagram)
                    {
                        ObjectDiagram objD = (ObjectDiagram)diagram;
                        if (objD.AttributeList != null)
                        {
                            foreach (Attribute attr in objD.AttributeList)
                            {
                                this.AddAttrRelations(attr);
                            }
                        }
                        if (objD.MethodList != null)
                        {
                            foreach (Method m in objD.MethodList)
                            {
                                this.AddMethodRelations(m);
                            }
                        }
                    }

                }
            }
        }


        public void AddAttrRelations(Attribute attr)
        {
            this.AddAttrAssoState(attr);
            this.AddAttrParentAttr(attr);
        }

        public void AddAttrAssoState(Attribute attr)
        {
            if (attr.assoStateId!=null)
            {
                attr.assoState = mDAO.findDiagramById(attr.assoStateId);
            }
        }

        public void AddAttrParentAttr(Attribute attr)
        {
            if (attr.parentAttrId!=null)
            {
                attr.parentAttr = mDAO.findAttrById(attr.parentAttrId);
            }
        }



        public void AddMethodRelations(Method m)
        {
            this.AddMethodAssoInfo(m);
            this.AddMethodParentMethod(m);
        }

        public void AddMethodAssoInfo(Method m)
        {
            if (m.assoInfoId != null)
            {
                m.assoInfo = mDAO.findDiagramById(m.assoInfoId);
            }
        }

        public void AddMethodParentMethod(Method m)
        {
            if (m.parentMethodId != null)
            {
                m.parentMethod = mDAO.findMethodById(m.parentMethodId);
            }
        }
// 
//         public void AddMethodIsComplex(Method m)
//         {
//             if ()
//             {
//             } 
//             else
//             {
//             }
//         }
    }
}
